﻿@model YiYiTong.Rocket.Entity.MenuInfo

@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<form action="@Url.Action("AddMenu", "Menu")" method="post" class="definewidth m20">
    <table class="table table-bordered table-hover definewidth m10">
        <tr>
            <td colspan="2">
                <h5>
                    @ViewBag.Title，请填写菜单信息，标<em>*</em>号是必填或必选项。
                </h5>
                <input type="hidden" value="@Model.menuId" name="MenuID" />
            </td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">菜单代码<em>*</em></td>
            <td><input type="text" id="MenuCode" name="MenuCode" maxlength="100" value="@Model.menuCode" /></td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">菜单名称<em>*</em></td>
            <td><input type="text" name="MenuName" maxlength="100" value="@Model.menuName" /></td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">菜单地址<em>*</em></td>
            <td><input type="text" name="MenuUrl" maxlength="150" value="@Model.menuUrl" /></td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">父菜单<em>*</em></td>
            <td>
                @Html.Action("DropListMenuList", "Menu", new { EleAttr = new ElementAttribute { Class = "sce-wid02", Name = "ParentID" }, ParentID = Model.parentID })
            </td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">是否可见<em>*</em></td>
            <td>
                <input type="radio" name="IsVisible" style="vertical-align:middle; margin-bottom:6px;" value="0" checked />可见
                <input type="radio" name="IsVisible" style="vertical-align:middle; margin-bottom:6px;" value="1" />不可见
            </td>
        </tr>
        <tr>
            <td class="tableleft">备注</td>
            <td><textarea name="Remark" style="width:240px;" maxlength="250" cols="4">@Model.remark</textarea></td>
        </tr>
        <tr>
            <td class="tableleft"></td>
            <td>
                <p><span id="spMsg"></span></p>
                <button type="submit" class="btn btn-primary">保存</button> &nbsp;&nbsp;
                <button type="button" class="btn btn-success" name="backid" id="backid">返回</button>
            </td>
        </tr>
    </table>
    <script>
        BUI.use('bui/overlay', function (overlay) {
            function showSucc(obj, url) {
                BUI.Message.Alert(obj, function () {
                    location.href = url;
                }, 'success');
            }

            $(function () {
                //绑定是否可见
                switch ('@Model.isVisible') {
                    case '0':
                        $("input[name=IsVisible]").get(0).checked = true;
                        break;
                    case '1':
                        $("input[name=IsVisible]").get(1).checked = true;
                        break;
                }

                $('#backid').on('click', function () {
                    window.document.location.href = "@Url.Action("MenuList", "Menu")";
                });

                //判断中文字符
                jQuery.validator.addMethod("isChinese", function (value, element) {
                    return this.optional(element) || /^[\u0391-\uFFE5\-]+$/.test(value);
                }, "只能包含中文,-等字符");

                //判断只能字母
                jQuery.validator.addMethod("IsLetter", function (value, element) {
                    return this.optional(element) || /^[a-zA-Z]+$/.test(value);
                }, "只能包含字母");


                var validator = $('form').validate({
                    errorLabelContainer: $("#errorContainer"),
                    errorElement: "span",
                    rules: {
                        MenuCode: { required: true, IsLetter: true },
                        MenuName: { required: true, isChinese: true }
                    },
                    messages: {
                        MenuCode: { required: "菜单代码不能为空", IsLetter: "菜单代码只能只能包含字母" },
                        MenuName: { required: "菜单名称不能为空", isChinese: "菜单名称只能包含中文,-等字符" }
                    },
                    submitHandler: function (form) {
                        $(form).ajaxSubmit(function (result) {
                            if (result.Message != undefined) {
                                if (result.IsSuccess) {
                                    showSucc(result.Message, result.Body);
                                }
                                else {
                                    $("#spMsg").html(result.Message);
                                }
                                return false;
                            }
                            else {
                                var substr = cutstr(result, "BUI.Message.Alert", "function");
                                substr = substr.replace("'", "").replace("'", "").replace("(", "").replace(",", "");
                                if (substr == "")
                                    BUI.Message.Alert("操作失败，请联系技术人员", 'warning');
                                else {
                                    if (substr.indexOf("请重新登录") > 0) {
                                        BUI.Message.Alert(substr, function () {
                                            top.location.href = "@Url.Action("Login","User")";
                                        }, 'warning');
                                    }
                                    else {
                                        BUI.Message.Alert(substr, 'warning');
                                    }
                                }
                            }
                        });
                    }
                });
            });
        });
    </script>
</form>
